package cn.pfund.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.pfund.entity.CompanyinfoType;
import cn.pfund.service.CompanyinfoTypeService;
import cn.pfund.dao.CompanyinfoTypeDao;
import cn.pfund.util.Pagination;
import cn.pfund.util.ParamBean;
import cn.pfund.util.QueryCondition;

@Service("companyinfoTypeService")
public class CompanyinfoTypeServiceImpl extends BaseServiceImpl implements CompanyinfoTypeService {
	@Resource(name="companyinfoTypeDao")
    private CompanyinfoTypeDao companyinfoTypeDao;
    
    @Transactional(readOnly = true)
	public Pagination<CompanyinfoType> getPagination(ParamBean paramBean) {
		List<QueryCondition> queryConditions = new ArrayList<QueryCondition>();
		if (StringUtils.isNotBlank(paramBean.getKeyword())) {
			queryConditions.add(new QueryCondition(paramBean.getField(), QueryCondition.LK, paramBean.getKeyword()));
		}
		String orderBy = "order by orders asc";
		Pagination<CompanyinfoType> pagination = (Pagination<CompanyinfoType>)getPagination(CompanyinfoType.class, queryConditions, orderBy, paramBean.getPage(), paramBean.getPageSize());
		pagination.setPageHtml(paramBean.getUrl());
		return pagination;
	}

    @Transactional(readOnly = true)
	public List<CompanyinfoType> getAllCompanyinfoType() {
		return getAllCompanyinfoType(null);
	}
    
    @Transactional(readOnly = true)
	public List<CompanyinfoType> getAllCompanyinfoType(Integer belongto) {
    	List<QueryCondition> queryConditions = new ArrayList<QueryCondition>();
    	if (belongto != null && belongto.intValue() > 0) {
    		queryConditions.add(new QueryCondition("belongto", QueryCondition.EQ, belongto));
		}
    	String orderBy = "order by orders asc";
		return get(CompanyinfoType.class, queryConditions, orderBy);
	}
}
